const bcrypt = require('bcryptjs')
const { sequelize } = require('../core/dbchange')
const {Sequelize, Modal} = require('sequelize')

class Admin extends Modal {

}

// 初始用户模型
Admin.init({
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    nickname: Sequelize.STRING,
    // 管理员邮箱
    email: {
        type: Sequelize.STRING(128),
        unique: true
    },
    password: {
        type: Sequelize.STRING,
        set(val) {
            const salt = bcrypt.genSaltSync(10);
            const psw = bcrypt.hashSync(val, salt);
            this.setDataValue('password',psw)
        }
    }
},{
    sequelize,
    tableName: 'admin'
})

module.exports = {
    Admin
}